<template>
  <div style="margin-top: 60px;margin-left:80px;border: 0px solid red;" >
    <el-form style="margin-left: -40px" :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="字段：" prop="key">
        <el-select v-model="ruleForm.key" style="width: 160px;float: left" placeholder="请选择字段">
          <el-option label="职位名称" value="reName"></el-option>
          <el-option label="申请人姓名" value="name"></el-option>
        </el-select>
      </el-form-item>
      <div style="border: 0px solid red;width: 400px;height: 60px;position: relative;top: -64px;left: 270px">
        <el-form-item label="值：">
          <el-input v-model="ruleForm.value" placeholder="请输入关键字" style="width: 160px;"></el-input>
          <el-button type="primary" icon="el-icon-search" style="position: relative;left: 10px;" @click="submitForm('ruleForm')">搜索</el-button>
        </el-form-item>
      </div>
    </el-form>

    <el-table
            :data="tableData"
            border
            stripe
            style="width: 1150px;position: relative;top:-30px">
      <el-table-column
              fixed
              prop="rid"
              label="申请人ID"
              width="100">
      </el-table-column>
      <el-table-column
              prop="name"
              label="申请人姓名"
              width="120">
      </el-table-column>
      <el-table-column
              prop="phone"
              label="申请人电话"
              width="120">
      </el-table-column>
      <el-table-column
              prop="email"
              label="申请人邮箱"
              width="120">
      </el-table-column>
      <el-table-column
              prop="reName"
              label="职位名称"
              width="120">
      </el-table-column>
      <el-table-column
              prop="contactName"
              label="负责人姓名"
              width="120">
      </el-table-column>
      <el-table-column
              prop="contactPhone"
              label="负责人电话"
              width="120">
      </el-table-column>
      <el-table-column
              prop="interviewTime"
              label="面试时间"
              width="120">
      </el-table-column>
      <el-table-column
              prop="interviewPlace"
              label="面试地点"
              width="120">
      </el-table-column>
      <el-table-column
              prop="state"
              label="状态"
              width="100">
      </el-table-column>
    </el-table>
    <el-pagination style="margin-top: 20px;float: right"
                   background
                   layout="prev, pager, next"
                   :page-size="pageSize"
                   :total="total"
                   :current-page.sync="currentPage"
                   @current-change="page">
    </el-pagination>
  </div>

</template>

<script>
  export default {
    data() {
      return {
        tableData: null,
        currentPage: 1,
        pageSize: 4,
        total: null,
        key: '',
        value: '',
        resume:'',
        ruleForm: {
          key: '',
          value: '',
          page: '',
          size: 4
        },
        rules: {
          key: [
            { required: true, message: '请选择字段', trigger: 'change' }
          ]
        }
      }
    },
    methods:{
      submitForm(formName) {
        const _this = this
        //让翻页复原
        _this.currentPage=1
        this.$refs[formName].validate((valid) => {
          if (valid) {
            const _this = this
            _this.ruleForm.page = _this.currentPage
            axios.get('http://localhost:8182/application/search2'+"/"+_this.resume.rid,{params:_this.ruleForm}).then(function (resp) {
              _this.tableData = resp.data.data.data
              _this.total = resp.data.data.total
            })
          }
        });

      },
      page(currentPage){
        const _this = this
        if(_this.ruleForm.value == ''){
          axios.get('http://localhost:8182/application/list3/'+currentPage+'/'+_this.pageSize+"/"+_this.resume.rid).then(function (resp) {
            _this.tableData = resp.data.data.data
            _this.total = resp.data.data.total
          })
        } else {
          _this.ruleForm.page = _this.currentPage
          axios.get('http://localhost:8182/application/search2'+"/"+_this.resume.rid,{params:_this.ruleForm}+"/").then(function (resp) {
            _this.tableData = resp.data.data.data
            _this.total = resp.data.data.total
          })
        }

      }
    },
    created() {
      let resume = JSON.parse(window.localStorage.getItem('resume'))
      this.resume = resume
      const _this = this
      axios.get('http://localhost:8182/application/list3/1/'+_this.pageSize+"/"+_this.resume.rid).then(function (resp) {
        _this.tableData = resp.data.data.data
        _this.total = resp.data.data.total
      })
    }
  }
</script>